﻿using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

namespace ASPNETVN.PORTAL.Modules.PhotoAlbum.Components
{
    public partial class Collection
    {
        public static DataSet SelectFullAll(int moduleID)
        {
            string spName = "[dbo].p_PhotoAlbum_Collection_SelectFullAll";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@ModuleID", SqlDbType.Int, moduleID);
            return db.ExecuteDataSet(dbCommand);
        }

        public static DataSet SelectFullBy(int id)
        {
            string spName = "[dbo].p_PhotoAlbum_Collection_SelectFullBy_ID";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@ID", SqlDbType.Int, id);
            return db.ExecuteDataSet(dbCommand);
        }

        public static string GetCoverFileName(int id)
        {
            string filename = string.Empty;
            string query = "SELECT FileName FROM t_PhotoAlbum_Pictures WHERE CollectionID = " + id;
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetSqlStringCommand(query);
            IDataReader reader = db.ExecuteReader(dbCommand);
            if (reader.Read())
            {
                filename = reader["FileName"].ToString();
            }
            reader.Close();
            dbCommand.Connection.Close();
            return filename;
        }
    }
}
